home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
pascal
/
gsdbloo.exe
/
GS_GENF.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1992-02-29
|
11KB
|
369 lines
Unit GS_GenF;
{------------------------------------------------------------------------------
DBase File Builder
Copyright (c) Richard F. Griffin
20 February 1992
102 Molded Stone Pl
Warner Robins, GA 31088
-------------------------------------------------------------
This unit creates a test dBase file and adds records to an
existing test file.
The unit uses two external files to generate data. The first is
TESTDATA.FIL, which contains names and addresses the routines use
to randomly generate data. The second file is WISDOM.FIL, which
contains one-liners used to randomly create memo fields. Each of
these files may be modified to fit the user's requirements.
File structure is:
LASTNAME C 30 0
FIRSTNAME C 30 0
STREET C 30 0
OFFICE C 30 0
CITY C 30 0
STATE C 2 0
ZIP C 10 0
TELEPHONE C 20 0
BIRTHDATE D 8 0
PAYMENT N 9 2
PAIDFLAG L 1 0
RANDOMNUM N 12 5
UNIQUEID C 8 0
COMMENTS M 10 0 (Only included if Memo Field requested)
The MakeTestData unit is called as follows for database creation:
MakeTestData(namFile, numRecs, MemoAlso);
where:
namFile = file name without the file extension
numRecs = number of records to insert
MemoAlso = boolean true to create a memo file and records,
false to omit a memo field.
The AddTestData unit is called as follows for additional records:
AddTestData(namObjt, numRecs);
where:
namObjt = Pointer to the GS_dBFld_Objt object for the file
numRecs = number of records to add
-------------------------------------------------------------------------------}
interface
{$D-}
uses
CRT,
DOS,
GS_Date,
GS_Objts,
GS_Strng,
GS_MakMo,
GS_dBase,
GS_dBFld,
GS_dB3Wk;
procedure MakeTestData(namFile : string; numRecs : integer;
MemoAlso : boolean);
procedure AddTestData(namObjt : GSP_dBFld_Objt; numRecs : integer);
implementation
const
CollectionsEmpty : boolean = true;
yearweight : array [0..6] of word
= (7665,14600,14600,23725,32850,40150,40150);
memoweight : array [0..7] of word
= (0,500,500,1000,1500,1000,500,500);
type
FldRecPtr = ^FldRecTyp;
FldRecTyp = array[1..GS_dBase_MaxRecField] of GS_dBase_Field;
var
fli : text;
flp : text;
s : string;
i,
j,
k : integer;
x : integer;
gfMemoColl : GS_MakeMemoP;
gfMemoArray : array[0..50] of word;
gfMemoLines : integer;
gfMemoBytes : longint;
gfMemoAvg : integer;
gfLastName : string[30];
gfFirstName : string[30];
gfStreet : string[80];
gfOffice : string;
gfState : string[2];
gfZip : string[5];
gfCity : string[30];
gfTelePhone : string[20];
gfBirthDate : string[8];
gfPayment : string[9];
gfPaidFlag : string[1];
gfRandomNum : string[12];
gfUniqueID : string[8];
SZC : string;
MoColl,
LNColl,
FNColl,
StColl,
OfColl,
SZColl : TCollection;
f : FldRecPtr;
t : string;
FLoc : integer;
dbx : GSP_dBFld_Objt;
useMemo : boolean;
procedure InsertField(s : string; t : char; l,d : integer);
begin
if FLoc >= GS_dBase_MaxRecField then exit;
inc(FLoc);
s := AllCaps(s);
CnvStrToAsc(s,f^[FLoc].FieldName,11);
f^[FLoc].FieldType := t;
f^[FLoc].FieldLen := l;
f^[FLoc].FieldDec := d;
f^[FLoc].FieldAddress := 0;
FillChar(f^[FLoc].Reserved,20,#0);
end;
procedure MakeCollections;
begin
FileMode := 66;
assign(fli,'testdata.fil');
reset(fli);
LNColl.Init(32,32);
FNColl.Init(32,32);
StColl.Init(32,32);
OfColl.Init(32,32);
SZColl.Init(32,32);
x := 0;
readln(fli,s);
while not EOF(fli) do
begin
s := TrimR(s);
if s[1] = '%' then
begin
if s = '%LASTNAME' then x := 1;
if s = '%FIRSTNAME' then x := 2;
if s = '%STREET' then x := 3;
if s = '%OFFICE' then x := 4;
if s = '%STATEZIPCITY' then x := 5;
end
else
case x of
1 : LNColl.Insert(NewStr(s));
2 : FNColl.Insert(NewStr(s));
3 : StColl.Insert(NewStr(s));
4 : OfColl.Insert(NewStr(s));
5 : SZColl.Insert(NewStr(s));
end;
readln(fli,s);
end;
close(fli);
if not useMemo then exit;
gfMemoBytes := 0;
assign(fli,'wisdom.fil');
reset(fli);
MoColl.Init(2000,500);
readln(fli,s);
while not EOF(fli) do
begin
s := TrimR(s);
gfMemoBytes := gfMemoBytes + ord(s[0]);
MoColl.Insert(NewStr(s));
readln(fli,s);
end;
close(fli);
gfMemoAvg := gfMemoBytes div MoColl.Count;
end;
Function RandString(l,h : integer) : string;
var
v : integer;
g : string;
begin
v := random((h-l)+1);
v := v + l;
str(v,g);
RandString := g;
end;
procedure BuildRecordData;
var
i1,
j1,
j2,
k1 : word;
i2 : longint;
tf : boolean;
s1 : string[5];
begin
j := random(LNColl.Count);
gfLastName := PString(LNColl.At(j))^;
j := random(FNColl.Count);
gfFirstName := PString(FNColl.At(j))^ + ' ' + chr(Random(26)+65) + '.';
j := random(StColl.Count);
gfStreet := RandString(10,9999) + ' ' + PString(StColl.At(j))^;
j := random(OfColl.Count*3);
if j < OfColl.Count then
gfOffice := PString(OfColl.At(j))^ + ' ' + RandString(1,99)
else gfOffice := '';
j := random(SZColl.Count);
s := PString(SZColl.At(j))^;
gfState := copy(s,1,2);
gfZip := copy(s,3,5);
gfCity := copy(s,8,30);
gfTelePhone := RandString(100,600) + ' ' + RandString(100,999) + '-' +
RandString(1000,9999);
i1 := yearweight[random(7)];
i2 := random(i1)+1;
gfBirthDate := GS_Date_dBStor(GS_Date_Curr - i2);
i1 := random(20000) + 1;
str(i1:6,gfPayment);
gfPayment := gfPayment + '.' + RandString(10,99);
i1 := random(2);
if i1 = 0 then gfPaidFlag := 'F' else gfPaidFlag := 'T';
i1 := random(2);
if i1 = 0 then gfRandomNum := '-' else gfRandomNum := '';
s1 := RandString(0,30000);
while length(s1) < 5 do s1 := s1+'0';
gfRandomNum := gfRandomNum + RandString(0,30000) + '.' + s1;
while length(gfRandomNum) < 12 do gfRandomNum := ' ' + gfRandomNum;
gfUniqueID := Unique_Field;
if not useMemo then exit;
gfMemoColl^.ResetMemoData;
j2 := random(8);
j2 := memoweight[j2];
if j2 = 0 then exit;
s := '--- ' + gfLastName + ', ' + gfFirstName + ' Memo Record';
gfMemoColl^.InsertMemoData(s+#13#10);
gfMemoLines := random(j2 div gfMemoAvg);
i1 := 0;
while i1 <= gfMemoLines do
begin
j1 := random(MoColl.Count);
tf := true;
if i1 > 0 then
for k1 := 0 to i1 do if j1 = gfMemoArray[k1] then tf := false;
if tf then
begin
s := PString(MOColl.At(j1))^;
gfMemoColl^.InsertMemoData(s+#13#10);
gfMemoArray[i1] := j1;
inc(i1);
end;
end;
end;
procedure MakeTestData(namFile : string; numRecs : integer;
MemoAlso : boolean);
begin
useMemo := MemoAlso;
if CollectionsEmpty then MakeCollections;
CollectionsEmpty := false;
{Create new dBase file}
New(f);
FLoc := 0;
InsertField('LASTNAME','C',30,0);
InsertField('FIRSTNAME','C',30,0);
InsertField('STREET','C',30,0);
InsertField('OFFICE','C',30,0);
InsertField('CITY','C',30,0);
InsertField('STATE','C',2,0);
InsertField('ZIP','C',10,0);
I